package com.sdu.shanyimisapi.service.impl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import com.sdu.shanyimisapi.db.dao.MisUserDao;
import com.sdu.shanyimisapi.service.MisUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author lihaopeng
 * @version 1.0
 * @project shanyi-mis-api
 * @description MIS端用户
 * @since 2024/4/13 12:27
 */
@Service
public class MisUserServiceImpl implements MisUserService {

    @Resource
    private MisUserDao misUserDao;
    @Override
    public Integer login(Map param) {
        // getStr()可以从Map里获取出字符串
        String username = MapUtil.getStr(param,"username");
        String password = MapUtil.getStr(param,"password");
        // MD5是hutool工具库里的一个类，用来进行MD5加密
        MD5 md5 = MD5.create();
        String temp = md5.digestHex(username);
        // 前六位字符
        String tempStart = StrUtil.subWithLength(temp,0,6);
        // 后三位字符
        String tempEnd = StrUtil.subSuf(temp,temp.length() - 3);
        // 混淆原始密码并哈希加密
        password = md5.digestHex(tempStart + password + tempEnd);
        param.replace("password", password);
        Integer userId = misUserDao.login(param);
        return userId;
    }

}
